package ee.rsi2m.goproject;


import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

public class NewMatchActivity extends Activity implements OnClickListener {
	public Bundle gameSettings = new Bundle();
	public double[] settingsArray = new double[4];
	public static Typeface typeface;

	public void onClick(View v) {

		switch (v.getId()) {

		case R.id.size_nine:
			settingsArray[0] = 9;
			break;
		case R.id.size_thirteen:
			settingsArray[0] = 13;
			break;
		case R.id.size_nineteen:
			settingsArray[0] = 19;
			break;

		case R.id.handicap_null:
			settingsArray[1] = 0;
			break;
		case R.id.handicap_one:
			settingsArray[1] = 1;
			break;
		case R.id.handicap_two:
			settingsArray[1] = 2;
			break;
		case R.id.handicap_three:
			settingsArray[1] = 3;
			break;
		case R.id.handicap_four:
			settingsArray[1] = 4;
			break;
		case R.id.handicap_five:
			settingsArray[1] = 5;
			break;
		case R.id.handicap_six:
			settingsArray[1] = 6;
			break;
		case R.id.handicap_seven:
			settingsArray[1] = 7;
			break;
		case R.id.handicap_eight:
			settingsArray[1] = 8;
			break;
		case R.id.handicap_nine:
			settingsArray[1] = 9;
			break;

		case R.id.scoring_chinese:
			settingsArray[2] = 0;
			break;
		case R.id.scoring_japanese:
			settingsArray[2] = 1;
			break;

		case R.id.komi5:
			settingsArray[3] = 5.5;
			break;
		case R.id.komi6:
			settingsArray[3] = 6.5;
			break;
		case R.id.komi7:
			settingsArray[3] = 7.5;
			break;
		case R.id.komi8:
			settingsArray[3] = 8.5;
			break;

		case R.id.startGame:
			if (settingsArray[0] != 0) {
				SharedPreferences myPrefs = this.getSharedPreferences("myPrefs", MODE_WORLD_READABLE);
		        SharedPreferences.Editor prefsEditor = myPrefs.edit();
		        prefsEditor.putInt("boardSize", (int) settingsArray[0]);
		        prefsEditor.commit();
		        
				gameSettings.putDoubleArray("settingsArray", settingsArray);
				Intent gameIntent = new Intent(this, GameActivity.class);
				gameIntent.putExtras(gameSettings);
				startActivity(gameIntent);
				break;
			}
		}

	}

	public void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.newgame);
		typeface = Typeface.createFromAsset(getAssets(),
		        "fonts/times.ttf");

		findViewById(R.id.size_nine).setOnClickListener(this);
		findViewById(R.id.size_thirteen).setOnClickListener(this);
		findViewById(R.id.size_nineteen).setOnClickListener(this);
		findViewById(R.id.handicap_null).setOnClickListener(this);
		findViewById(R.id.handicap_one).setOnClickListener(this);
		findViewById(R.id.handicap_two).setOnClickListener(this);
		findViewById(R.id.handicap_three).setOnClickListener(this);
		findViewById(R.id.handicap_four).setOnClickListener(this);
		findViewById(R.id.handicap_five).setOnClickListener(this);
		findViewById(R.id.handicap_six).setOnClickListener(this);
		findViewById(R.id.handicap_seven).setOnClickListener(this);
		findViewById(R.id.handicap_eight).setOnClickListener(this);
		findViewById(R.id.handicap_nine).setOnClickListener(this);
		findViewById(R.id.scoring_chinese).setOnClickListener(this);
		findViewById(R.id.scoring_japanese).setOnClickListener(this);
		findViewById(R.id.komi5).setOnClickListener(this);
		findViewById(R.id.komi6).setOnClickListener(this);
		findViewById(R.id.komi7).setOnClickListener(this);
		findViewById(R.id.komi8).setOnClickListener(this);
		findViewById(R.id.startGame).setOnClickListener(this);

	}

}
